<?php
/**
 * Created by PhpStorm.
 * User: Rei
 * Date: 16/5/8
 * Time: 14:48
 * Mail: rei@king.moe
 */

namespace Home\Controller;

use Think\Controller;

class NewsController extends Controller
{
    public function read(){
        $id = I('get.id/d');

        $data = D('News')->getNews($id);
        $notification = D('Subscribe')->getSubNotify();
        $mostcomment = D('Subscribe')->getMostComment();
        $user = D('User')->getUser();

        $this->assign(array('user'=>$user ,'notification'=>$notification, 'mostcomment'=>$mostcomment));
        $this->assign($data);
        $this->display('news/index');
    }


    //瀑布流API
    public function waterfall(){

        $result = array(
            'success' => TRUE,
            'message' => 'Retrieved pictures',
            'data' => array()
        );

        $page = I('get.page/d', 1);
        $type = I('get.type/s', '');
        $keyword = I('get.keyword', '');
        $size = 10;

        $data = D('News')->getWaterfallData($page, $size, $type, $keyword);
        $max_page = D('News')->getMaxPage($size);

        $result['data'] = $data;

        if(empty($data) || $page >= $max_page){
            $result['success'] = TRUE;
            $result['message'] = 'No more news';
        }

        $this->ajaxReturn($result, 'json');
    }

}